package shiyan33;
import java.util.HashMap;
import java.util.Map;

public class MapExample {
    public static void main(String[] args) {
        // 创建HashMap存储学生成绩
        Map<String, Integer> studentGrades = new HashMap<>();
        
        // 添加一些学生信息
        studentGrades.put("张三", 85);
        studentGrades.put("李四", 90);
        studentGrades.put("王五", 78);
        studentGrades.put("赵六", 92);
        
        // 查找特定学生并更新成绩
        String studentName = "李四";
        if (studentGrades.containsKey(studentName)) {
            int currentGrade = studentGrades.get(studentName);
            System.out.println(studentName + "当前成绩: " + currentGrade);
            
            // 成绩提高10分(但不超过100分)
            int newGrade = Math.min(currentGrade + 10, 100);
            studentGrades.put(studentName, newGrade);
            System.out.println(studentName + "更新后成绩: " + newGrade);
        } else {
            System.out.println("找不到学生: " + studentName);
        }
        
        // 打印更新后的Map
        System.out.println("更新后的学生成绩表:");
        for (Map.Entry<String, Integer> entry : studentGrades.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}